package com.timeDeal.servlet;


import com.timeDeal.bean.JingbiaoBean;
import com.timeDeal.bean.PageList;
import com.timeDeal.bean.UserBean;
import com.timeDeal.service.JIngbiaoServicce;
import com.timeDeal.service.ShijianchusouService;
import com.timeDeal.service.UserService;
import com.timeDeal.service.XuqiuService;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * Created by Administrator on 2016/7/24.
 */

public class WodeJingbiaoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String currentpage = request.getParameter("currentpage");
        String flag = StringUtils.defaultString(request.getParameter("flag"), "0");
        XuqiuService xuqiuService = new XuqiuService();
        UserBean loginuser = (UserBean) request.getSession().getAttribute("USER");
        currentpage = StringUtils.equals(currentpage, null) ? "1" : currentpage;
        PageList pageList = new PageList();
        int cu = Integer.valueOf(currentpage);
        UserService userService = new UserService();
        System.out.println(flag+"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP");
        JIngbiaoServicce jIngbiaoServicce = new JIngbiaoServicce();
        if(com.alibaba.druid.util.StringUtils.equals(flag,"0")){
            System.out.println(flag+"1111111");
            pageList = jIngbiaoServicce.getJingbiaoById(cu, loginuser.getYonghuid());
            System.out.println(pageList.getList().size()+"2222222");
            for (Object o : pageList.getList()) {
                int name = ((JingbiaoBean) o).getXuqiufabuid();
                System.out.println(name);
                String mm = xuqiuService.getAxuquById(name).getXuqiumingcheng();
                ((JingbiaoBean) o).setXuqiufabumingcheng(mm);
            }
            System.out.println(flag+"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP");
            System.out.println(pageList.getList().size()+"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP");
            request.setAttribute("pageList", pageList);
            request.setAttribute("currentpage", currentpage);
            request.getRequestDispatcher("/user/wodejingbiao.jsp").forward(request, response);

        }else {
            System.out.println(flag+"1111111");
            pageList = jIngbiaoServicce.getJingbiaoByIdAndShijian(cu, loginuser.getYonghuid());
            ShijianchusouService shijianchusouService = new ShijianchusouService() ;
            System.out.println(flag+"22222222");
            for (Object o : pageList.getList()) {
                int name = ((JingbiaoBean) o).getShijianchushouid();
                String mm = shijianchusouService.getAShijianChushouById(name).getShijianchushoumingcheng();
                ((JingbiaoBean) o).setShijianchushoumingcheng(mm);
            }
            System.out.println(pageList.getList().size()+"PPPPPPPPPPPPPPPPPPPPPPPPPPPP");
            request.setAttribute("pageList", pageList);
            request.setAttribute("currentpage", currentpage);
            request.getRequestDispatcher("/user/shijianchushou/wodejingbiao.jsp").forward(request, response);
        }


    }
}
